package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxConsult;
import com.ruoyi.system.service.fx.IFxConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 咨询Controller
 *
 * @author ruoyi
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/system/consult")
public class FxConsultController extends BaseController {
    @Autowired
    private IFxConsultService fxConsultService;

    /**
     * 查询咨询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxConsult fxConsult) {
        startPage();
        List<FxConsult> list = fxConsultService.selectFxConsultList(fxConsult);
        return getDataTable(list);
    }

    /**
     * 导出咨询列表
     */
    @Log(title = "咨询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxConsult fxConsult) {
        List<FxConsult> list = fxConsultService.selectFxConsultList(fxConsult);
        ExcelUtil<FxConsult> util = new ExcelUtil<FxConsult>(FxConsult.class);
        util.exportExcel(response, list, "咨询数据");
    }

    /**
     * 获取咨询详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxConsultService.selectFxConsultById(id));
    }

    /**
     * 新增咨询
     */
    @Log(title = "咨询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxConsult fxConsult) {
        return toAjax(fxConsultService.insertFxConsult(fxConsult));
    }

    /**
     * 修改咨询
     */
    @Log(title = "咨询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxConsult fxConsult) {
        return toAjax(fxConsultService.updateFxConsult(fxConsult));
    }

    /**
     * 删除咨询
     */
    @Log(title = "咨询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxConsultService.deleteFxConsultByIds(ids));
    }
}
